home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / csp9606a.zip / CSPLIT.C next >
C/C++ Source or Header  |  1996-06-02  |  38KB  |  1,250 lines

  1. /*
  2.  * Donated to public domain
  3.  *
  4.  * Designation:  CSplit
  5.  *
  6.  * Description:  This program is used to process source files for
  7.  *               the purpose of transmission through a FidoNet (tm)
  8.  *               echo in such a manner as to circumvent over-size
  9.  *               message problems.
  10.  *
  11.  *  This program implements the following specifications:
  12.  *
  13.  *  1) a. Combine multiple source files.
  14.  *     b. Split source into 90 line sections.
  15.  *     c. Add header and trailer marker lines delimiting each
  16.  *        section and file.
  17.  *  2) a. Delete any trailing whitespace.
  18.  *     b. Replace tabs with spaces honoring tabstop boundaries.
  19.  *     c. Default to 4 columns per tabstop.
  20.  *     d. Allow user to specify alternate tabstop column number.
  21.  *  3) a. Wrap lines longer than 75 characters long using the C
  22.  *        "\ at the end of a line" notation (using space break).
  23.  *     b. Distinguish wrapped lines from user-continued lines by
  24.  *        inserting a line with a single "\" character between the
  25.  *        two lines that contain the wrapped text.
  26.  *  4) a. Calculate a CRC for each section and include it in the
  27.  *        section trailer marker lines.
  28.  *  5) a. Provide a help display for program usage when the
  29.  *        program is executed without parameters.
  30.  *  6) a. Provide as detailed of explanation as possible when
  31.  *        an unexpected condition occurs.
  32.  *     b. Attempt to continue execution for all but the most severe
  33.  *        errors.
  34.  *
  35.  *
  36.  * Syntax:
  37.  *
  38.  * Split:     CSPLIT  [/tn] [/wn] [/ln] [/sc]  outfile  src.ext [ ... ]
  39.  *
  40. |* Extract:   CSPLIT  /x  infile  [ ... ]
  41.  *
  42.  * Where:      /t n - For TAB character expansion, the number of columns
  43.  *                    for each TAB stop.  (defaults to every 4 columns)
  44.  *             /w n - For width control, the column number to be used for
  45.  *                    breaking long lines.  (the default is column 75)
  46.  *             /l n - For length control, the number of lines to limit
  47. |*                    each section or 0 for no split.  (default is 90)
  48.  *             /s c - Use 'c' as an alternate line separator character
  49.  *                    instead of the default separator character, '>'.
  50. |*                    Ignored for extraction - matches separator found
  51. |*                    in extract file.  However, the extract file must
  52. |*                    only use one separator character.
  53.  *           infile - Input file name.  An extension indicates that the
  54.  *                    file contains the sections in proper consecutive
  55. |*                    order ready for extraction.  Otherwise, infile.001,
  56. |*                    infile.002, etc., will be used.
  57. |*          outfile - Name of the output file(s).  The extension will
  58. |*                    be ignored if specified and each output file will
  59. |*                    be named such that the section number will be the
  60. |*                    extension (e.g., outfile.001, outfile.002, etc..)
  61.  *          src.ext - The first source file..etc  Wildcard filespecs are
  62.  *                    supported only under non-ANSI compiling conditions.
  63.  *
  64. |* Notes:  Paths are supported for all filenames, however, the paths
  65. |*         are not preserved internally during the split operation.
  66. |*         The extraction process will therefore only create files in
  67. |*         the current directory.
  68.  *
  69.  * Revision History:  ( thanks to all the contributors )
  70.  *
  71.  * 08/31/93  Fred Cole  Original draft
  72.  * 09/05/93  Fred Cole  Added CRC calculation and extraction ability.
  73.  *                      Fixed a line wrap problem.
  74.  * 09/14/93  Fred Cole  Added conditional compilation directives to
  75.  *                      allow non-ANSI filespec support.  Squashed an
  76.  *                      extract() function bug.
  77.  * 11/21/93  Thad Smith Test for incomplete input file on extraction.
  78.  *                      Remove spaces added in message transmission.
  79.  *                      Default to 90 lines/section.  Fix tab expansion.
  80.  * 12/03/93  Fred Cole  Fixed a cleanup() function bug.
  81.  * 12/09/93  Keith Campbell / TS
  82.  *                      Fixed bug with options preceded by '-' and fixed
  83.  *                      tempfile opening bug.
  84.  * 01/02/94  David Nugent / FC
  85.  *                      Additions for findfirst/findnext support for
  86.  *                      MSC6 (& 7) and OS/2 in initlist() routine and
  87.  *                      portable.h header file.
  88.  * 01/02/94  Auke Reitsma / FC
  89.  *                      Increased number of chars read in to prevent line
  90.  *                      numbers from becoming out-of-sync with input.
  91.  * 01/12/94  Chad Wagner / FC
  92.  *                      Correction to initlist() function to eliminate
  93.  *                      redundant line increment.
  94.  *--- v2.0 --------------------------------------------------------------
  95.  * 07/23/94  Keith Campbell / FC
  96.  *                      Modified to not abort extraction when a CRC
  97.  *                      mismatch occurs - just issue warning message.
  98.  * 07/30/94  Auke Reitsma / FC
  99.  *                      Added multiple file extraction ability.
  100.  * 09/17/94  Keith Campbell / FC
  101.  *                      Added version separator lines.
  102.  * 10/28/94  Bob Stout / FC
  103.  *                      Added separator character, width and length
  104.  *                      command line options.
  105.  * 12/18/94  Fred Cole  Revised code to facilitate maintenance.
  106.  * 12/27/94  Fred Cole  Limited the minimum width for breaking long
  107.  *                      lines to column 55 since this is the length
  108.  *                      of the longest separator line.
  109.  * 01/15/95  David Gersic / FC
  110.  *                      Modified the line wrap logic to handle long
  111.  *                      sequences of characters lacking whitespace.
  112.  *--- v2.1 --------------------------------------------------------------
  113.  * 10/30/95  Phi Nguyen / FC
  114.  *                      Added file extraction messages.
  115.  * 10/31/95  Fred Cole  Added ability to extract unconcatenated files.
  116.  *                      Added path support except for extracted files
  117.  *                      ( i.e., paths are not preserved internally ).
  118.  * 11/06/95  Fred Cole  Corrected tabstop calculation on wrapped lines.
  119.  * 11/07/95  Fred Cole  Increased max section length to SHRT_MAX lines.
  120.  * 11/08/95  Bob Stout / FC
  121.  *                      Disable the split logic when a 0 section length
  122.  *                      is specified with the /L command line option.
  123.  *--- v2.2 --------------------------------------------------------------
  124.  * 11/22/95  Fred Cole  Modified logic to ignore leading whitespace added
  125.  *                      to separator lines ( mail reader quoting? ).
  126.  * 11/22/95  Doug Nazar (DN2) / FC
  127.  *                      Modified sscanf() format specifiers to correctly
  128.  *                      convert CRC values for 32 bit platforms.
  129.  * 11/22/95  Fred Cole  Changed TRUE/FALSE enum to macros to accommodate
  130.  *                      systems where these identifiers already exist.
  131.  * 11/29/95  Bob Stout / FC
  132.  *                      Added unsigned casts to allow signed 'length' to
  133.  *                      be compared to SHRT_MAX on 16-bit platforms.
  134.  * 11/29/95  Doug Nazar (DN2) / FC
  135.  *                      Added setbuf() statement to unbuffer stdout.
  136.  * 06/02/96  Fred Cole  Renamed TRUE/FALSE macros to avoid possible
  137.  *                      identifier conflicts.
  138.  * 06/02/96  Darin McBride / FC
  139.  *                      Modified logic to allow source files located on
  140.  *                      on another drive to be processed.  This change
  141.  *                      assumes that ':' is not a valid character for a
  142.  *                      file name.
  143.  * 06/02/96  Fred Cole  Corrected error in extract logic when file does
  144.  *                      not exist.
  145.  */
  146.  
  147. #include <ctype.h>
  148. #include <stdio.h>
  149. #include <stdlib.h>
  150. #include <string.h>
  151. #include <limits.h>
  152. #include "csplit.h"
  153.  
  154. char tempfile[MAXFSPEC + 1]; /* necessary evils - global variables */
  155. FILE *finp = NULL;
  156. FILE *fout = NULL;
  157. FILE *ftmp = NULL;
  158. SLST *head = NULL;
  159. SLST *cur  = NULL;
  160.  
  161. int main (int argc, char *argv[])
  162. {
  163.   char     sepc